<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{
    public function index()
    {
        //查询轮播图
        $picture = M('lb_picture')->field('lb_picture')->select();
        //获取轮播图总数
        $count = count($picture);
        //导航条的颜色选中
        $index  = 'navcolor';
        $title = '村点乐 - 首页';
        $this->assign('title', $title);
        $this->assign('count', $count);
        $this->assign('picture',$picture);
        $this->assign('index',$index);
        $this->display();
    }

    //首页的app介绍界面
    public function application()
    {
        $title = '村点乐 - 首页 - app介绍';
        //导航条的颜色选中
        $index  = 'navcolor';
        $this->assign('title', $title);
        $this->assign('index', $index);
        $this->display();
    }

    //走进村点乐页面
    public function brand()
    {
        $title = '村点乐 - 走进村点乐';
        //导航条的颜色选中
        $brand  = 'navcolor';
        $this->assign('title', $title);
        $this->assign('brand', $brand);
        $this->display();
    }

    //进入村点乐--购物环境页面
    public function shopping_environment()
    {
        $title = '村点乐 - 走进村点乐 - 购物环境';
        //导航条的颜色选中
        $brand  = 'navcolor';
        $this->assign('title', $title);
        $this->assign('brand', $brand);
        $this->display();
    }

    //进入村点乐--购物环境页面
    public function store_service()
    {
        $title = '村点乐 - 走进村点乐 - 门店服务';
        //导航条的颜色选中
        $brand  = 'navcolor';
        $this->assign('title', $title);
        $this->assign('brand', $brand);
        $this->display();
    }

    //进入村点乐--购物环境页面
    public function staff_mien()
    {
        $title = '村点乐 - 走进村点乐 - 员工风采';
        //导航条的颜色选中
        $brand  = 'navcolor';
        $this->assign('title', $title);
        $this->assign('brand', $brand);
        $this->display();
    }

    //进入APP下载页面
    public function app()
    {
        $title = '村点乐 - app下载';
        //导航条的颜色选中
        $app = 'navcolor';
        $this->assign('title', $title);
        $this->assign('app', $app);
        $this->display();
    }

    //进入成功案例页面
    public function successful()
    {
        //查询所有文章分类
        $article_cate_list = M('article_cate')
            ->field('id, article_cate_name')
            ->where(array('article_parent_id' => 1, 'status' => 1))
            ->order('sort')
            ->select();
        //遍历查询分类下面对应的文章标题、图片、简介、和具体文章内容（默认查询第一个文章分类的文章）
        $id = I('id');
        if($id == '')
        {
            $id = $article_cate_list[0]['id'];
        }
        $row = 3;
        $page = $_GET['p'];
        if ($page == '') {
            $page = 1;
        }
        $article_list = M('article')
            ->field('id, title, picture, content')
            ->where(array('article_cate_id' => $id))
            ->page($page, $row)
            ->select();
        $article_num = M('article')->where(array('article_cate_id' => $id))->count();
        $Page = new \Think\Page($article_num, $row);
        $show = $Page->show();
        $title = '村点乐 - 成功案例';
        //导航条的颜色选中
        $successful = 'navcolor';
        $this->assign('title', $title);
        $this->assign('successful', $successful);
        $this->assign('article_cate_list', $article_cate_list);
        $this->assign('article_list', $article_list);
        $this->assign('page', $show);
        $this->display();
    }

    //进入成功案例详情页面
    public function success_details()
    {
        //查询所有文章分类
        $article_cate_list = M('article_cate')
            ->field('id, article_cate_name')
            ->where(array('article_parent_id' => 1, 'status' => 1))
            ->order('sort')
            ->select();

        //查询该文章标题，作为title
        $article_info = M('article')->where(array('id' => I('id')))->find();
        $article_info['detail'] = htmlspecialchars_decode($article_info['detail']);
        $title = $article_info['title'];
        //导航条的颜色选中
        $successful = 'navcolor';
        $this->assign('title', $title);
        $this->assign('successful', $successful);
        $this->assign('article_cate_list', $article_cate_list);
        $this->assign('article_info', $article_info);
        $this->display();
    }

    //我要加盟页面
    public function cooperation()
    {
        $title = '村点乐 - 我要加盟';
        //导航条的颜色选中
        $cooperation = 'navcolor';
        $this->assign('title', $title);
        $this->assign('cooperation', $cooperation);
        $this->display();
    }

    //加入我们页面
    public function about_us()
    {
        $title = '村点乐 - 加入我们';
        //导航条的颜色选中
        $about_us = 'navcolor';
        //获取招聘职位列表
        $job_list = M('job_info')->where(array('status' => 1))->order('sort asc')->select();
        foreach($job_list AS $k => $v)
        {
            $job_list[$k]['job_describe'] = htmlspecialchars_decode($v['job_describe']);
        }

        $this->assign('title', $title);
        $this->assign('about_us', $about_us);
        $this->assign('job_list', $job_list);
        $this->display();
    }
}